<template>
  <div class="dict-group-div">
    <slot></slot>
  </div>
</template>

<script>
import {postRequest} from "@/axio2";

export default {
  name: "DictGroupComponent",
  data(){
    return{
      dictSet:new Set,
      dictData:new Map,
      dictGroup:[]
    }
  },
  methods:{
    getDictData:function (group, key) {
      return this.dictData[group][key];
    },
    getDictDataForDefault:function (group, key, defaultData) {
      let dictValue = this.dictData[group][key];
      if(undefined===dictValue || ""===dictValue){
        return defaultData;
      }
      return dictValue;
    },
    setDictData(resp,component){
      /*
       * 字典数据结构：
       * {
       *   "001"(GroupCode):{
       *      "01"(Key):"A"(Value),
       *      "02"(Key):"B"(Value)
       *   },
       *   "002"(GroupCode):{
       *      "03"(Key):"C"(Value),
       *      "04"(Key):"B"(Value)
       *   }
       * }
       */
      this.dictData = JSON.parse(resp.data.errorMsg);
    },
    getDictGroup(groupCode){
      return this.dictData[groupCode];
    }
  },
  mounted() {
    postRequest(
        "dict/forgeDictGet.do",
        {groupCodeArr:this.dictGroup},
        this.setDictData,
        null,
        this
    );
  }
}
</script>

<style scoped>
.dict-group-div{
  display: none;
}
</style>